import unittest
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from ddt import ddt,data,unpack
from util.read_csv import CSVUtil

# 读取外部csv文件里的数据，把读到的数据存储在一个变量d里
filePath="..\\testdata\\testdata1.csv"
u=CSVUtil(filePath)
d=u.get_list_data()
print(d)#为了调试，打印d的值

@ddt
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.driver=webdriver.Chrome(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')
        self.driver.implicitly_wait(14)

    def tearDown(self) -> None:
        sleep(3)
        self.driver.quit()

    @data(*d)
    @unpack
    def test_something(self,kw,expected):
        self.driver.get("http://127.0.0.1/upload/index.php")
        self.driver.find_element(By.ID,"keyword").send_keys(kw)
        self.driver.find_element(By.NAME,"imageField").click()
        actual=self.driver.find_element(By.XPATH,"//div[@id='pager']/span/b").text
        self.assertEqual(expected,actual)


if __name__ == '__main__':
    unittest.main()
